<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();

/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：tudougeaini
 邮箱：877873666@qq.com

 **** 版权所有 **** */


//打开用户表，并检测用户是否登录
$MB->Open('','login');

$skin->WebTop('应用推送升级系统');


echo('
<script language="javascript" type="text/javascript" src="js/appShop.js?v='. OT_VERSION .'"></script>
');


switch($mudi){
	case 'update':
		updateWeb();
		break;

	default :
		$MB->IsAdminRight('alertBack');
		defWeb();
		break;

}

$skin->WebBottom();

$MB->Close();
$DB->Close();





function defWeb(){
	global $DB,$mudi,$skin,$sysAdminArr,$authUrlArr;

	$dataMode	= OT::GetStr('dataMode');
	$dbName		= OT::GetStr('dbName');
	$page		= OT::GetInt('page');
	$refContent	= OT::GetRegExpStr('refContent','sql');
		if (! in_array($dataMode,array('app','tpl','pack','idc','buy','user','user2'))){ $dataMode = 'buy'; }
		if ($refContent == '请输入插件关键字'){ $refContent = ''; }

	$paraArr = OTauthArr();

	$userMarkStr = '';
	if ($dataMode == 'user' && $sysAdminArr['SA_checkUrlMode'] != 0){
		$userMarkStr = '<span style="color:red;">['. Adm::UrlWebMode($sysAdminArr['SA_checkUrlMode']) .']</span>';
	}
	echo('
	<div class="tabMenu" rel="no">
	<div style="float:right;padding:6px 5px 0 0;"><input type="button" style="color:blue;" value="更新已购插件信息" onclick=\'DataDeal.location.href="appShop_deal.php?mudi=getInfo&mode=back&backURL="+ encodeURIComponent(document.location.href);\' /></div>
	<ul>
		<li onclick=\'document.location.href="?dataMode=app";return false;\' '. ($dataMode=='app' ? 'class="selected"' : '') .'>功能插件</li>
		<li onclick=\'document.location.href="?dataMode=tpl";return false;\' '. ($dataMode=='tpl' ? 'class="selected"' : '') .'>模板插件</li>
		<li onclick=\'document.location.href="?dataMode=pack";return false;\' '. ($dataMode=='pack' ? 'class="selected"' : '') .'>插件套餐</li>
		<li onclick=\'document.location.href="?dataMode=buy";return false;\' '. ($dataMode=='buy' ? 'class="selected"' : '') .'>已购买的插件</li>
		<li><a href="http://check.idccms.com/shopUsers.php" style="color:#000;" target="_blank">会员中心</a></li>
		<li onclick=\'document.location.href="?dataMode=user";return false;\' '. ($dataMode=='user' ? 'class="selected"' : '') .'>会员中心'. $userMarkStr .'(框架模式，兼容性差)</li>
	</ul>
	<!-- <span style="position:relative;"><div style="position:absolute;left:-198px;top:2px;"><a href="http://check.idccms.com/shopUsers.php" target="_blank"><img src="images/img_newWin.png" /></a></div></span> -->
	'. Adm::StudyShow('appShop','<div style="padding:10px 0 0 0;font-size:14px;color:red;">&ensp;&ensp;&ensp;&ensp;<a href="http://otcms.com/news/8193.html" target="_blank" style="color:red;font-size:14px;">《插件平台使用说明》</a></div>') .'
	</div>
	');

	if (in_array($dataMode, array('app','tpl','pack','idc'))){
		// app:功能插件, tpl:模板插件, pack:插件套餐, idc:IDC插件
		$fileStr = ReqUrl::UseAuto($sysAdminArr['SA_getUrlMode'], 'POST', $authUrlArr[0] .'appListIdccms.php?mudi='. $dataMode .'&dataMode='. $dataMode .'&dbName='. $dbName .'&phpVer='. PHP_VERSION .'&OT_UPDATETIME='. OT_UPDATETIME .'&userID='. $sysAdminArr['SA_softID'] .'&username='. $sysAdminArr['SA_username'] .'&agentUserID='. $sysAdminArr['SA_agentUserID'] .'&page='. $page .'&isRef=1&refContent='. urlencode($refContent), 'UTF-8', $paraArr, 'note');
		if (strpos($fileStr,'(idcCMS)') === false){
			$fileStr = '数据获取错误（'. $fileStr .'）';
		}

		echo('
		<div id="tab'. ucfirst($dataMode) .'Shop">
			'. $fileStr .'
		</div>
		');
		if (in_array($dataMode,array('app','tpl'))){
			$payArr = AdmArea::GetAppIdArr();	// 获取已购买插件appID数组
			$payStr = implode(',',$payArr);
			echo('
			<script language="javascript" type="text/javascript">
			CheckPayBtn("'. $payStr .'");
			</script>
			');
		}
	}elseif ($dataMode=='user'){
		// 会员中心
		echo('
		<div id="tabUser">
			<iframe id="otcmsUser" name="otcmsUser" frameborder="0" allowTransparency="true" scrolling="auto" style="width:100%;height:780px;" src="'. $authUrlArr[0] .'shopUsers.php?url='. urlencode(GetUrl::CurrDir()) .'&domain='. urlencode(GetUrl::Domain(GetUrl::Main())) .'&OT_UPDATETIME='. OT_UPDATETIME .'&phpVer='. PHP_VERSION .'&username='. $sysAdminArr['SA_username'] .'&softID='. $sysAdminArr['SA_softID'] .'&softCode='. $sysAdminArr['SA_softCode'] .'&domainID='. $sysAdminArr['SA_domainID'] .'&domainCode='. $sysAdminArr['SA_domainCode'] .'&agentUserID='. $sysAdminArr['SA_agentUserID'] .'"></iframe>
		</div>
		');

	}elseif ($dataMode=='user2'){
		// 会员中心（https协议）
		$authUrlArr[0] = 'https://check.idccms.com/';
		echo('
		<div id="tabUser">
			<iframe id="otcmsUser2" name="otcmsUser2" frameborder="0" allowTransparency="true" scrolling="auto" style="width:100%;height:780px;" src="'. $authUrlArr[0] .'shopUsers.php?url='. urlencode(GetUrl::CurrDir()) .'&domain='. urlencode(GetUrl::Domain(GetUrl::Main())) .'&OT_UPDATETIME='. OT_UPDATETIME .'&phpVer='. PHP_VERSION .'&username='. $sysAdminArr['SA_username'] .'&softID='. $sysAdminArr['SA_softID'] .'&softCode='. $sysAdminArr['SA_softCode'] .'&domainID='. $sysAdminArr['SA_domainID'] .'&domainCode='. $sysAdminArr['SA_domainCode'] .'&agentUserID='. $sysAdminArr['SA_agentUserID'] .'&phpVer='. PHP_VERSION .'"></iframe>
		</div>
		');


	}else{
		// 已购买的插件
		echo('
		<div id="tabBuy">
			<div id="loginBox" style="font-size:14px;padding:0 0 12px 8px;line-height:1.6;">
				<form id="loginForm" name="loginForm" method="post" action="appShop_deal.php?mudi=getAuth" onsubmit="return CheckLoginForm()">
				<input type="hidden" id="pwdMode" name="pwdMode" value="" />
				<input type="hidden" id="pwdKey" name="pwdKey" value="" />
				<input type="hidden" id="pwdEnc" name="pwdEnc" value="" />
				<input type="hidden" id="softID" name="softID" value="'. $sysAdminArr['SA_softID'] .'" />
				<input type="hidden" id="softCode" name="softCode" value="'. $sysAdminArr['SA_softCode'] .'" />
				<input type="hidden" id="domainID" name="domainID" value="'. $sysAdminArr['SA_domainID'] .'" />
				<input type="hidden" id="domainCode" name="domainCode" value="'. $sysAdminArr['SA_domainCode'] .'" />
				<input type="hidden" id="agentUserID" name="agentUserID" value="'. $sysAdminArr['SA_agentUserID'] .'" />
				<input type="hidden" id="agentUsername" name="agentUsername" value="'. $sysAdminArr['SA_agentUsername'] .'" />
				
				登录用户名：<input type="text" id="username" name="username" value="'. $sysAdminArr['SA_username'] .'" style="width:125px;" />&ensp;&ensp;
				密码：<input type="password" id="userpwd" name="userpwd" style="width:125px;" />&ensp;&ensp;
				销售代理：'. ($sysAdminArr['SA_agentUserID'] == 0 ? '无' : '<span style="color:blue;">'. $sysAdminArr['SA_agentUsername'] .'</span>') .'<!-- <input type="text" id="agent" name="agent" value="'. $sysAdminArr['SA_agentUsername'] .'" style="width:125px;" title="默认走官方渠道，填写代理商走代理渠道价格" /> -->&ensp;&ensp;
				<input type="submit" value="授权获取" class="button1" />&ensp;&ensp;
				<span style="color:red;">（登录后，获取最新插件信息）</span>
			</div>
			');


			// 已订购的套餐
			$skin->TableTop2('share_show.gif','','已订购的套餐');
			$packexe = $DB->query('select * from '. OT_dbPref .'paySoftPack order by PSP_ID DESC');
			if (! $row = $packexe->fetch()){
				echo('
				<tr>
					<td align="center" style="padding:6px;">无订购任何套餐，<a href="?dataMode=pack" style="color:red;">点击查看《插件套餐》列表</a>.</td>
				</tr>
				');
			}else{
				echo('
				<tr>
					<td width="4%"></td>
					<td width="16%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="8%"></td>
					<td width="8%"></td>
					<td width="30%"></td>
					<td width="8%"></td>
				</tr>
				<tr class="tabColor1">
					<td align="center" style="padding:3px;font-weight:bold;">编号</td>
					<td align="center" style="padding:3px;font-weight:bold;">套餐名称</td>
					<td align="center" style="padding:3px;font-weight:bold;">购买日期</td>
					<td align="center" style="padding:3px;font-weight:bold;">到期日期</td>
					<td align="center" style="padding:3px;font-weight:bold;">价格</td>
					<td align="center" style="padding:3px;font-weight:bold;">续费</td>
					<td align="center" style="padding:3px;font-weight:bold;">插件列表</td>
					<td align="center" style="padding:3px;font-weight:bold;">操作</td>
				</tr>
				<tbody class="tabBody padd5td">
				');

				$dataNum = 0;
				do {
					$dataNum ++;
					if ($dataNum % 2 == 0){ $bgcolor='class="tabColorTr"'; }else{ $bgcolor=''; }

					$listNote = '';
					if ($row['PSP_list'] == 'all'){
						$listNote = '<span style="color:red;">（不会自动增加全部插件，需要到【功能插件】【模板插件】免费获取需要的插件）</span>';
					}
					echo('
					<tr '. $bgcolor .'>
						<td align="center">'. $dataNum .'</td>
						<td align="center">'. $row['PSP_theme'] .'</td>
						<td align="center">'. $row['PSP_buyDate'] .'</td>
						<td align="center">'. Area::DateDiffStr($row['PSP_updateDate']) .'</td>
						<td align="right" style="padding-right:8px;">'. $row['PSP_money'] .'</td>
						<td align="right" style="padding-right:8px;">'. $row['PSP_xufei'] .'</td>
						<td align="left">'. $row['PSP_nameList'] . $listNote .'</td>
						<td align="center">
							<span style="color:blue;cursor:pointer;" onclick=\'parent.OT_OpenAppShopUpdate('. $row['PSP_packID'] .',"&appType=pack&mode=xufei");\'>[续费]</span>
						</td>
					</tr>
					');

				}while ($row = $packexe->fetch());
			}
			unset($packexe);

			echo('
			</tbody>
			</table>
			<br />
			');

			// 已订购的插件
			$orderName = OT::ListDefVal(OT::GetStr('orderName'), 'theme|buyDate|useDate|updateDate|buyCost|cost|currTime|softTime|newTime|state', 'state');
			$orderSort = OT::ListDefVal(OT::GetStr('orderSort'), 'ASC', 'DESC');

			$pluFileArr = array();
			$pluFileArr = File::GetFileList(OT_ROOT .'plugin/', 'php');
			$pluFileArr = array_diff($pluFileArr, array('classApiAlidayu.php', 'classApiQQ.php', 'classApiTaobaoke.php', 'classApiWeibo.php', 'classApiWeixin.php', 'classApiWeixinLogin.php', 'classApiIdccms.php', 'classAppIdcPro.php', 'classAppIdcVps.php', 'classAppMoneyRecord.php', 'classAppTplIdc.php', 'classAppVpsApi.php', 'classAppVpsApiUc.php', 'classAppVpsApiUc2.php', 'classAppVpsApiDeal.php', 'classAppVpsApiWap.php', 'classAppIdccms.php', 'classAppTplYule.php'));

			$skin->TableTop2('share_show.gif','','已订购的插件&ensp;&ensp;（<label><input type="checkbox" id="judUpdateTr" value="1" onclick="ShowUpdateTr()" />只显示升级插件</label>）');
			$payexe = $DB->query('select * from '. OT_dbPref .'paySoft order by PS_state DESC,PS_'. $orderName .' '. $orderSort);
			if (! $row = $payexe->fetch()){
				echo('
				<tr>
					<td align="center" style="padding:6px;">无订购任何插件.</td>
				</tr>
				');
			}else{
				echo('
				<tr>
					<td width="4%"></td>
					<td width="16%"></td>
					<td width="8%"></td>
					<td width="8%"></td>
					<td width="8%"></td>
					<td width="6%"></td>
					<td width="11%"></td>
					<td width="10%"></td>
					<td width="10%"></td>
					<td width="6%"></td>
					<td width="13%"></td>
				</tr>
				<tr class="tabColor1">
					<td align="center" style="padding:3px;font-weight:bold;">编号</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('名称','theme',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('购买日期','buyDate',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('使用期限','useDate',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('升级期限','updateDate',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('买','buyCost',$orderName,$orderSort) .'/'. $skin->ShowArrow('续费','cost',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('当前版本','currTime',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('程序版本要求','softTime',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('最新版本','newTime',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">'. $skin->ShowArrow('状态','state',$orderName,$orderSort) .'</td>
					<td align="center" style="padding:3px;font-weight:bold;">操作</td>
				</tr>
				<tbody class="tabBody padd5td">
				');

				$pluArr = array();
				$pluArr['dataFreeNum'] = $pluArr['dataFreeUpNum'] = 0;		// 免费
				$pluArr['dataAppNum'] = $pluArr['dataAppUpNum'] = 0;		// 插件
				$pluArr['dataUsersNum'] = $pluArr['dataUsersUpNum'] = 0;	// 用户
				$pluArr['dataMoneyNum'] = $pluArr['dataMoneyUpNum'] = 0;	// 财务
				$pluArr['dataNewsNum'] = $pluArr['dataNewsUpNum'] = 0;		// 文章
				$pluArr['dataTplNum'] = $pluArr['dataTplUpNum'] = 0;		// 模板
				$pluArr['dataWapAppNum'] = $pluArr['dataWapAppUpNum'] = 0;	// WAP插件
				$pluArr['dataWapTplNum'] = $pluArr['dataWapTplUpNum'] = 0;	// WAP模板
				$pluArr['dataWeixinNum'] = $pluArr['dataWeixinUpNum'] = 0;	// 微信
				$pluArr['dataTaokeNum'] = $pluArr['dataTaokeUpNum'] = 0;	// 淘宝客
				$pluArr['dataIdcNum'] = $pluArr['dataIdcUpNum'] = 0;		// IDC系统
				$pluArr['dataDevNum'] = $pluArr['dataDevUpNum'] = 0;		// 开发者
				$pluArr['dataDiyNum'] = $pluArr['dataDiyUpNum'] = 0;		// 定制
				$buyMoney = $xufeiMoney = $guoqiMoney = 0;
				$appNum = $updateNum = $dataUpNum = 0;
				$appFileArr = array();
				$appArr = SysDiff::PluFileArr();	// 插件文件列表数组
				$state0Jud = false;
				do {
					$payCurrVer		= '';
					$payCurrTime	= '';
					$dbCurrVer		= '';
					$dbCurrTime		= '';
					$appNum ++;
					$row['PS_phpVer'] = floatval($row['PS_phpVer']);
					$row['PS_phpVerMax'] = floatval($row['PS_phpVerMax']);
					if (isset($pluArr[$row['PS_appType'] .'Num'])){ $pluArr[$row['PS_appType'] .'Num'] ++; }
					$dataUpNum += $row['PS_updateNum'];
					if ($row['PS_state'] == 1){
						$buyMoney += $row['PS_buyCost'];
						$xufeiMoney += $row['PS_cost'];
						if (strtotime($row['PS_updateDate']) < time()){ $guoqiMoney += $row['PS_cost']; }
					}
					if ($appNum % 2 == 0){ $bgcolor = 'tabColorTr'; }else{ $bgcolor = ''; }
					if (isset($appArr[$row['PS_appID']])){
						$pluFileArr = array_diff($pluFileArr, $appArr[$row['PS_appID']]);
						if ($row['PS_state'] == 0){
							foreach ($appArr[$row['PS_appID']] as $item0){
								$pluFileArr = array_diff($pluFileArr, array('del_'. $item0));
							}
						}
					}

					if (File::IsExists(OT_ROOT .'cache/web/appVer_'. $row['PS_appID'] .'.txt')){
						$verArr = Str::SplitBr(trim(File::Read(OT_ROOT .'cache/web/appVer_'. $row['PS_appID'] .'.txt')));
						if (count($verArr)>=6){
							$payCurrVer		= OT::NumFormat($verArr[2],2);
							$payCurrTime	= intval($verArr[3]);
							$dbCurrVer		= OT::NumFormat($verArr[4],2);
							$dbCurrTime		= intval($verArr[5]);
						}
					}

//					if ($payCurrTime == ''){ $payCurrVer=$row['PS_currVer']; $payCurrTime=$row['PS_currTime']; }
					
					$updateStyleStr = $updateImgStr = $themeAddi = '';
					if (intval($row['PS_newTime']) > $payCurrTime || strlen($row['PS_currTime'])==0){
						// $updateImgStr='<div style="position:relative;"><div style="position:absolute;left:25px; top:-22px;" title="点击进入在线升级"><img src="images/newVer.gif" onclick=\'CheckUpdateBox();$id("updateV2Box").src="updateV2.php?appID='. $row['PS_appID'] .'&appType='. $row['PS_appType'] .'";\' style="cursor:pointer;" /></div></div>';
						// $updateImgStr='<div style="color:red;cursor:pointer;" onclick=\'OT_OpenAppShopUpdate('. $row['PS_appID'] .',"&appType='. $row['PS_appType'] .'");\' title="点击进入升级">[有新版本]</div>';
						$bgcolor .= ' updateVerTr';
						$updateStyleStr = 'color:red;cursor:pointer;';
						$updateImgStr = '<div><img src="images/newVer.gif" /></div>';
						if (isset($pluArr[$row['PS_appType'] .'UpNum'])){ $pluArr[$row['PS_appType'] .'UpNum'] ++; }
					}else{
						$bgcolor .= ' normalVerTr';
					}
					if ($row['PS_payMode'] == 6){
						$themeAddi .= '<span style="color:blue;padding-top:2px;">【免费额度】</span>';
					}elseif ($row['PS_payMode'] == 9){
						$themeAddi .= '<span style="color:blue;padding-top:2px;">【插件套餐】</span>';
					}
					if ( $row['PS_phpVer'] > 0 ){				//  && OT::VerCompare($row['PS_phpVer']) < 0
						$themeAddi .= '<div style="color:'. (OT::VerCompare($row['PS_phpVer']) >= 0 ? '#cccccc' : 'red') .';padding-top:2px;" title="该插件要求PHP版本不低于v'. $row['PS_phpVer'] .'才能使用">【PHP版本≥'. $row['PS_phpVer'] .'】</div>';
					}
					if ( $row['PS_phpVerMax'] > 0 ){		//  && OT::VerCompare($row['PS_phpVerMax']) > 0
						$themeAddi .= '<div style="color:'. (OT::VerCompare($row['PS_phpVerMax']) <= 0 ? '#cccccc' : 'red') .';padding-top:2px;" title="该插件要求PHP版本不高于v'. $row['PS_phpVerMax'] .'才能使用">【PHP版本≤'. $row['PS_phpVerMax'] .'】</div>';
					}
					if ($row['PS_currTime'] == $payCurrTime){
						$currTimeStr = PayVerTimeStr($payCurrVer,$payCurrTime);
						if ($dbCurrTime >= 20210318){
							if ($row['PS_dbTime'] != $dbCurrTime && $dbCurrVer . $row['PS_dbVer'] != '1.00'){
								$currTimeStr .= '<div style="color:red;margin-top:6px;">（DB≠'. $dbCurrTime .'）</div>';
							}
						}else{
							if (strlen(''. $row['PS_dbTime']) > 0 && $row['PS_dbTime'] != $dbCurrTime){
								$currTimeStr .= '<div style="color:red;margin-top:6px;">（DB≠'. $dbCurrTime .'）</div>';
							}
						}
					}else{
						$currTimeStr = '<span style="text-decoration:line-through;">'. PayVerTimeStr($row['PS_currVer'],$row['PS_currTime']) .'</span>';
						if (strlen($payCurrTime) == 0){
							$currTimeStr .= '<div style="color:red;">异常！到[会员中心]-[域名管理]-[插件列表]-重新升级</div>';
						}elseif (strlen($row['PS_currTime']) == 0 && $row['PS_state'] == 1){
							$currTimeStr .= '<div style="color:red;">请先升级，不然无法使用该插件功能</div>';
						}
					}
					if ($row['PS_state'] == 0 && $state0Jud == false){
						$state0Jud = true;
						echo('
						</tbody>
						<tr><td id="adStopStr" colspan="11" class="padd8 pointer" align="center" style="font-size:16px;font-weight:bold;background:#e9e7e7;color:blue;padding:10px;" onclick=\'ClickShowHidden("state0Box");\'>
							→ 点击显示【已禁用的插件 <span style="color:red;">'. intval($DB->GetOne('select count(PS_ID) from '. OT_dbPref .'paySoft where PS_state=0')) .'</span> 个】 ←
						</td></tr>
						<tbody id="state0Box" class="tabBody padd5td" style="display:none;">
						');
					}
					echo('
					<tr class="'. $bgcolor .'">
						<td align="center">'. $appNum .'</td>
						<td align="center"><span title="'. $row['PS_type'] .'">'. $row['PS_theme'] .'</span><div>'. $themeAddi .'</div></td>
						<td align="center">'. $row['PS_buyDate'] .'<div style="color:#c9c9c9;" title="升级次数">'. $row['PS_updateNum'] .'</div></td>
						<td align="center">'. Area::DateDiffStr($row['PS_useDate']) .'</td>
						<td align="center">'. Area::DateDiffStr($row['PS_updateDate']) .'</td>
						<td align="right" style="padding-right:8px;"><div style="color:;" title="购买价">'. $row['PS_buyCost'] .'</div><div style="color:blue;" title="续费价">'. $row['PS_cost'] .'</div></td>
						<td align="center" title="本地版本：V'. $payCurrVer .'_'. $payCurrTime .'&#10;记录版本：V'. $row['PS_currVer'] .'_'. $row['PS_currTime'] .'&#10;本地数据库：V'. $dbCurrVer .'_'. $dbCurrTime .'&#10;记录数据库：V'. $row['PS_dbVer'] .'_'. $row['PS_dbTime'] .'">'. $currTimeStr .'</td>
						<td align="center">V'. $row['PS_softVer'] .' '. $row['PS_softTime'] .'</td>
						<td align="center" style="'. $updateStyleStr .'" onclick=\'OT_OpenAppShopUpdate('. $row['PS_appID'] .',"&appType='. $row['PS_appType'] .'");\' title="点击进入升级系统">'. $updateImgStr . PayVerTimeStr($row['PS_newVer'],$row['PS_newTime']) .'</td>
						<td align="center">'. Adm::SwitchBtn('paySoft',$row['PS_ID'],$row['PS_state'],'state','isUse2') .'</td>
						<td align="center">
							<span style="color:red;cursor:pointer;" onclick=\'parent.OT_OpenAppShopUpdate('. $row['PS_appID'] .',"&appType='. $row['PS_appType'] .'");\'>[升级]</span>
							<span style="color:blue;cursor:pointer;" onclick=\'parent.OT_OpenAppShopUpdate('. $row['PS_appID'] .',"&appType='. $row['PS_appType'] .'&mode=xufei");\'>[续费]</span>
							<a href="'. $row['PS_url'] .'" target="_blank" style="color:#000;">[详情]</a>
						</td>
					</tr>
					');
				}while ($row = $payexe->fetch());

				$pluStr = '';
				if ($pluArr['dataFreeNum'] > 0){
					$pluStr .= PluBtn('免费', $pluArr['dataFreeNum'], $pluArr['dataFreeUpNum']);
				}
				if ($pluArr['dataAppNum'] > 0){
					$pluStr .= PluBtn('常用', $pluArr['dataAppNum'], $pluArr['dataAppUpNum']);
				}
				if ($pluArr['dataUsersNum'] > 0){
					$pluStr .= PluBtn('用户', $pluArr['dataUsersNum'], $pluArr['dataUsersUpNum']);
				}
				if ($pluArr['dataMoneyNum'] > 0){
					$pluStr .= PluBtn('财务', $pluArr['dataMoneyNum'], $pluArr['dataMoneyUpNum']);
				}
				if ($pluArr['dataNewsNum'] > 0){
					$pluStr .= PluBtn('文章', $pluArr['dataNewsNum'], $pluArr['dataNewsUpNum']);
				}
				if ($pluArr['dataTplNum'] > 0){
					$pluStr .= PluBtn('模板', $pluArr['dataTplNum'], $pluArr['dataTplUpNum']);
				}
				if ($pluArr['dataWapAppNum'] > 0){
					$pluStr .= PluBtn('WAP插件', $pluArr['dataWapAppNum'], $pluArr['dataWapAppUpNum']);
				}
				if ($pluArr['dataWapTplNum'] > 0){
					$pluStr .= PluBtn('WAP模板', $pluArr['dataWapTplNum'], $pluArr['dataWapTplUpNum']);
				}
				if ($pluArr['dataWeixinNum'] > 0){
					$pluStr .= PluBtn('微信', $pluArr['dataWeixinNum'], $pluArr['dataWeixinUpNum']);
				}
				if ($pluArr['dataTaokeNum'] > 0){
					$pluStr .= PluBtn('淘宝客', $pluArr['dataTaokeNum'], $pluArr['dataTaokeUpNum']);
				}
				if ($pluArr['dataIdcNum'] > 0){
					$pluStr .= PluBtn('IDC系统', $pluArr['dataIdcNum'], $pluArr['dataIdcUpNum']);
				}
				if ($pluArr['dataDevNum'] > 0){
					$pluStr .= PluBtn('第三方', $pluArr['dataDevNum'], $pluArr['dataDevUpNum']);
				}
				if ($pluArr['dataDiyNum'] > 0){
					$pluStr .= PluBtn('定制', $pluArr['dataDiyNum'], $pluArr['dataDiyUpNum']);
				}
				echo('
				</tbody>
				<tr>
					<td colspan="11" align="center" style="padding:5px;"><div style="float:left;margin:3px;">插件统计：</div>'. $pluStr .'</td>
				</tr>
				<tr>
					<td colspan="11" align="center" style="padding:12px;font-weight:bold;">
						【已启用插件总计】购买金额： <span style="color:blue;">'. $buyMoney .'</span> 元<!-- ，续费金额： <span style="color:blue;">'. $xufeiMoney .'</span> 元 -->，过期续费金额：<span style="color:red;">'. $guoqiMoney .'</span> 元
					</td>
				</tr>
				');

				if ($dataUpNum == 0){
					echo('
					<tr><td colspan="11" class="padd8" align="center" style="color:red;font-size:16px;font-weight:bold;">【检测到插件都没升级记录，如果是重新安装或导入旧数据库，请重新升级所有插件，防止网站出现程序错误，如正常忽略该提示】</td></tr>
					');
				}
			}

			if ( count($pluFileArr) > 0 ){
				$DB->query('delete from '. OT_dbPref .'htmlFile where HF_mode="plugin"');
				$newArr = array();
				foreach ($pluFileArr as $file){
					$dataArr = array();
					$dataArr['HF_mode']		= 'plugin';
					$dataArr['HF_type']		= 'file';
					$dataArr['HF_dataID']	= 0;
					$dataArr['HF_theme']	= 'plugin插件目录下可能无用文件';
					$dataArr['HF_filePath']	= $file;
					$resJud = $DB->InsertParam('htmlFile',$dataArr);
					if ($resJud){
						$lastID = $DB->GetOne('select max(HF_ID) from '. OT_dbPref .'htmlFile');
						$newArr[] = '<span id="pluginFile'. $lastID .'">'. $file .'<a href="javascript:void();" onclick=\'if(confirm("你确定要删除文件“plugin/'. $file .'”？\n如有非官方插件或模板文件，请谨慎删除。\n如要删除建议先备份该文件再删除，以防误删还可恢复。")==true){DataDeal.location.href="appShop_deal.php?mudi=pluginFileDel&dataID='. $lastID .'"}return false;\' style="color:red;display:none;" class="delClass">[删除]</a></span>';
					}else{
						$newArr[] = '<span>'. $file .'</span>';
					}
				}

				echo('
				<tr><td colspan="11" class="padd8" align="left" style="color:blue;">【plugin插件目录下可能无用文件】'. implode('，',$newArr) .'&ensp;<span id="delClass" style="color:#000;cursor:pointer;" onclick=\'ClassShowHidden("delClass")\'>[删除管理]</span></td></tr>
				');
			}

			echo('
			</table>

			<div style="font-size:14px;color:red;font-weight:bold;padding:5px 5px 5px 6px;line-height:1.4;">
				提醒：1、插件是绑定域名使用，用非购买插件的域名登录后台会造成插件菜单不显示或插件不能使用的问题。<br />
				　　　2、一个账号可以管理多个网站，请勿一个网站注册一个账号，不利于管理。<br />
				　　　3、插件购买后，要马上升级，不然可能会出现程序错误或插件功能不显示，如暂时不想升级，插件状态设为禁用。<br />
				　　　4、如果有插件到期后不想续费，但还想使用，请不要升级后续程序版本，最新版程序需要最新版插件配合才能用。
			</div>

			<div class="tabMenuSubmit" style="text-align:center;margin:0 auto;padding-left:0;padding-bottom:15px;"><input type="button" class="btnBg" value="更新插件信息" onclick=\'document.location.href="appShop_deal.php?mudi=getInfo&backURL="+ encodeURIComponent(document.location.href);\' /></div>
		</div>
		');
	}
}


function updateWeb(){
	global $DB,$skin,$sysAdminArr,$authUrlArr;

	$appID		= OT::GetInt('appID');
	$appType	= OT::GetStr('appType');
	$mode		= OT::GetStr('mode');

	$appRow = $DB->GetRow('select PS_theme,PS_state from '. OT_dbPref .'paySoft where PS_appID='. $appID);
		if ($appRow){
			// die('<div style="padding:20px;font-size:14px;line-height:2;">搜索不到该插件信息，请确认该插件是否存在（'. $appID .'）。</div>');
			if ($appRow['PS_state'] == 0){
				die('<div style="padding:20px;font-size:14px;line-height:2;">【'. $appRow['PS_theme'] .'】插件当前状态：<b style="color:red;">已禁用</b>，请先 <b style="color:green;">启用</b> 再升级。</div>');
			}
		}
	unset($appRow);

	$beforeURL	= GetUrl::CurrDir(1);
	$updateUrlGetStr = '&OT_Database='. OT_Database .'&OT_UPDATETIME='. OT_UPDATETIME .'&OT_VERSION='. OT_VERSION .'&dataVer='. OT_UPDATEVER .'&phpVer='. PHP_VERSION .'&OT_URL='. urlencode($beforeURL) .'&username='. $sysAdminArr['SA_username'] .'&softID='. $sysAdminArr['SA_softID'] .'&softCode='. $sysAdminArr['SA_softCode'] .'&domainID='. $sysAdminArr['SA_domainID'] .'&domainCode='. $sysAdminArr['SA_domainCode'] .'&agentUserID='. $sysAdminArr['SA_agentUserID'] .'&appID='. $appID .'&appType='. $appType .'&mode='. $mode;

	$appBuyUrl = $authUrlArr[0] . OT_SOFTTYPE .'AppBuy.php?mudi=getAppInfo&adminUrl='. urlencode(GetUrl::CurrDir(0)) . $updateUrlGetStr;
	$retRes = ReqUrl::UseAuto($sysAdminArr['SA_getUrlMode'], 'GET', $appBuyUrl, 'UTF-8', array(), 'note');
	if (strpos($retRes,'[true]') === false){
		// die('<div style="padding:20px;font-size:14px;line-height:2;">'. $retRes .'</div>');
		JS::HrefEnd($appBuyUrl);
	}else{
		echo('<div style="padding:3px;font-size:14px;line-height:2;text-align:center;color:blue;font-weight:bold;">'. $retRes .'</div>');
		$dbName = Str::GetMark($retRes,'[dbName:',']');
		if (strlen($dbName) > 0){ $appType = $dbName; }
	}

	echo('
	<form id="updateForm" name="updateForm" method="post" action="updateV2.php?mudi=checkRight">
	<input type="hidden" id="updateEventStr" name="updateEventStr" value="" />
	<input type="hidden" id="updateFileNum" name="updateFileNum" value="" />
	<input type="hidden" id="updateFileSize" name="updateFileSize" value="" />
	<input type="hidden" id="updateVerInfo" name="updateVerInfo" value="" />
	<input type="hidden" id="updateVerTheme" name="updateVerTheme" value="" />

	<input type="hidden" id="runVerIdList" name="runVerIdList" value="" />
	<input type="hidden" id="checkFileListStr" name="checkFileListStr" value="" />
	<input type="hidden" id="updateVerListStr" name="updateVerListStr" value="" />
	<input type="hidden" id="updateFileListStr" name="updateFileListStr" value="" />
	<input type="hidden" id="updateVerPoint" name="updateVerPoint" value="" />
	<input type="hidden" id="updateFilePoint" name="updateFilePoint" value="" />

	<input type="hidden" id="updateErrUrl" name="updateErrUrl" value="about:blank" />
	<input type="hidden" id="updateConfigWindow" name="updateConfigWindow" value="" />
	</form>

	<table cellpadding="0" cellspacing="0" style="width:750px;">
	<tr>
		<td width="40%" align="left" valign="top" class="font1_1" style="padding:8px;line-height:2;">
			<div>1.尝试连接网钛科技升级系统 &ensp;<span id="updateV2Step1"></span></div>
			<div>2.检测所需的目录文件权限 &ensp;<span id="updateV2Step2"></span></div>
			<div>3.获取升级包更新文件 &ensp;<span id="updateV2Step3"></span></div>
			<div>4.运行升级过程 &ensp;<span id="updateV2Step4"></span></div>
			<div>5.升级完毕 &ensp;<span id="updateV2Step5"></span></div>
			<div style="color:#cccccc;cursor:pointer;" onclick="window.frames[\'updateV2Box\'].UpdateWinHeight(0)">[调整右侧升级框高度]</div>
		</td>
		<td width="60%" align="left" valign="top" style="padding:4px 8px 0 8px;">
			<input type="hidden" id="updateUrlGetStr" name="updateUrlGetStr" value="'. $updateUrlGetStr .'" />
			<span id="updateV2NoteStr"></span>
			<iframe id="updateV2Box" name="updateV2Box" width="98%" hei'.'ght="300" style="width:98%;hei'.'ght:300px;" frameborder="0" scrolling="no" allowtransparency="true" src="updateV2.php?appID='. $appID .'&appType='. $appType .'"></iframe>
		</td>
	</tr>
	</table>

	<div style="height:5px;overflow:hidden;"></div>
	</div>
	</div>
	');

}



function PayVerTimeStr($verStr, $verTimeStr){
	$retStr = '';
	if (strlen($verTimeStr)>3){
		$retStr = 'V'. $verStr .' '. $verTimeStr;
	}
	return $retStr;
}


function PluBtn($name, $num, $upNum){
	// return '<input type="button" value="'. $name .' '. $upNum .'/'. $num .'" style="margin-right:3px;" title="'. $name .'类插件有 '. $num .' 个，可更新 '. $upNum .' 个" />';
	return '<div style="float:left;margin:3px;" title="'. $name .'类插件有 '. $num .' 个，可更新 '. $upNum .' 个">['. $name .' '. $upNum .'/'. $num .']</div>';
}
?>